package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;

/**This class implements the GetAssigmnInfo from the DB
 *@author Gabi Revah
 *@author Aviad Almog
 *
 */
public class MessageGetAssigmnInfo {
	private ConnectionToClient client ;
	private String[] str;
	
/**
 * Constructor of this class 	
 * @param str
 * @param client
 */
	public MessageGetAssigmnInfo( String[] str, ConnectionToClient client){
		
		this.client= client ;
		this.str= str; 	
	
	}
/**
 * This method gets  the Assignment Info from the DB	
 * @throws SQLException
 * @throws IOException
 */
public void GetAssigmnInfo() throws SQLException, IOException{
		
		SQLConnection sc = new SQLConnection();
		java.sql.PreparedStatement asin = sc.getConnection().prepareStatement("SELECT assingment.discription FROM db.assingment where idassingment='"+str[1]+"';");
		ResultSet asinrs= asin.executeQuery();
		
		if (!asinrs.next() )
		{
			client.sendToClient("fail");

		}
		else
		{
			ArrayList<Object> arr=new ArrayList<Object>();
			arr.add("GetAssigmnInfo");
			arr.add(asinrs.getString(1));
			client.sendToClient(arr);
		}
	}

}
